/*
 * Copyright (C) 2017-2021
 * All rights reserved, Designed By
 * Copyright authorization contact 18814114118
 */
package com.shop.cereshop.app.page.login;

import java.util.Optional;

import com.shop.cereshop.commons.domain.buyer.CereBuyerUser;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 登录返回数据
 */
@Data
@Accessors(chain = true)
@ApiModel(value = "BuyerUser", description = "登录返回数据")
public class BuyerUser {
  /**
   * 微信昵称
   */
  @ApiModelProperty(value = "微信昵称")
  private String wechatName;

  /**
   * 微信openid
   */
  @ApiModelProperty(value = "微信openid")
  private String wechatOpenId;

  /**
   * 绑定手机号
   */
  @ApiModelProperty(value = "绑定手机号")
  private String phone;

  /**
   * 请求token
   */
  @ApiModelProperty(value = "请求token")
  private String token;

  /**
   * 请求token过期时间
   */
  @ApiModelProperty(value = "请求token过期时间(单位/秒)")
  private Long expire;

  /**
   * 刷新token
   */
  @ApiModelProperty(value = "刷新token")
  private String refreshToken;

  /**
   * 刷新token过期时间
   */
  @ApiModelProperty(value = "刷新token过期时间(单位/秒)")
  private Long refreshExpire;

  /**
   * 客户id
   */
  @ApiModelProperty(value = "客户id")
  private Long buyerUserId;

  /**
   * 是否启用状态 1-是 0-否
   */
  @ApiModelProperty(value = "是否启用状态 1-是 0-否")
  private Integer state;

  /**
   * 是否加入黑名单 1-是 0-否
   */
  @ApiModelProperty(value = "是否加入黑名单 1-是 0-否")
  private Integer ifBlack;

  /**
   * 微信加密秘钥
   */
  @ApiModelProperty(value = "微信加密秘钥")
  private String sessionKey;

  /**
   * 是否第一次登录 1-是 0-否
   */
  @ApiModelProperty(value = "是否第一次登录 1-是 0-否")
  private Integer ifFirst;

  /**
   * 头像图片
   */
  @ApiModelProperty(value = "头像图片")
  private String headImage;

  /**
   * 支付宝小程序用户id
   */
  @ApiModelProperty(value = "支付宝小程序用户id")
  private String aliUserId;

  /**
   * 会员等级id
   */
  @ApiModelProperty(value = "会员等级id")
  private Long memberLevelId;

  /**
   * 会员等级名称
   */
  @ApiModelProperty(value = "会员等级名称")
  private String memberLevelName;

  /**
   * 成长值
   */
  @ApiModelProperty(value = "成长值")
  private Integer growth;

  /**
   * 积分
   */
  @ApiModelProperty(value = "积分")
  private Integer credit;

  /**
   * 下一级需要的成长值
   */
  @ApiModelProperty(value = "下一级需要的成长值")
  private Integer nextLevelGrowth;

  /**
   * 下一级会员等级名称
   */
  private String nextLevelName;

  public static BuyerUser fromCereBuyerUser(CereBuyerUser user) {
    if (user == null) {
      return null;
    }
    BuyerUser buyerUser = new BuyerUser();
    buyerUser.setBuyerUserId(user.getBuyerUserId())
        .setPhone(user.getPhone())
        .setWechatName(user.getWechatName())
        .setWechatOpenId(user.getWechatOpenId())
        .setHeadImage(user.getHeadImage())
        .setMemberLevelId(user.getMemberLevelId())
        .setMemberLevelName(user.getMemberLevelName())
        .setGrowth(user.getGrowth())
        .setCredit(user.getCredit())
        .setNextLevelGrowth(user.getNextLevelGrowth())
        .setNextLevelName(user.getNextLevelName())
        .setIfBlack(user.getIfBlack())
        .setState(user.getState())
        .setAliUserId(user.getAliUserId())
        .setToken(user.getToken());
    return buyerUser;
  }
}
